/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mnstudent.presentationlayer;

import mnstudent.global.MyTableCellRender;
import mnstudent.global.DataTable;
import mnstudent.global.Standard;
import mnstudent.businessLayer.AcademicYearBLL;
import mnstudent.businessLayer.InfoSemesterYearBLL;
import mnstudent.businessLayer.SemesterBLL;
import mnstudent.datatranferobject.AcademicYearDTO;
import mnstudent.datatranferobject.FacultyDTO;
import mnstudent.datatranferobject.InfoSemesterYearDTO;
import mnstudent.datatranferobject.SemesterDTO;
import java.awt.Dimension;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.Vector;
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.table.DefaultTableModel;

/**
 *
 * @author lee
 */
public class frmInfoSemesterYear extends javax.swing.JPanel {

    private InfoSemesterYearBLL m_InfoSemesterYearBLL;
    private SemesterBLL m_SemesterBLL;
    private AcademicYearBLL m_AcademicYearBLL;
    private SemesterDTO objAddNewSemester;
    private AcademicYearDTO objAddNewYear;
    ArrayList<SemesterDTO> listSemesterObj;
    ArrayList<AcademicYearDTO> listYearObj;
    private int currentRow = 0;
    //private boolean m_isSave = false;
    private DefaultTableModel m_Model;
    private final SimpleDateFormat formatDate= new SimpleDateFormat("dd/MM/yyyy");
    
    /**
     * Creates new form frmFaculty
     */
    public frmInfoSemesterYear() {
        initComponents();
        initControls();
        prepare();
    }

    private void initControls()
    {
        jxTxtInfoSemesterYearID.setEditable(false);//luon luon false
        jxtabDetails.setEditable(false);
         //neu chua them moi thi EditTable = false
        if(!this.jxtabDetails.m_isAdd && !this.jxtabDetails.m_isUpdate)
        {
            jxCbSemester.setEnabled(false);
            jxCbYear.setEnabled(false);
            jxDpDateDealineFee.setEditable(false);
            jxDpDateDealinePromation.setEditable(false);
            jxDpDateDealineRegistration.setEditable(false);
            jxDpDateStartRegistration.setEditable(false);
            
            jxSpRatePromotion.setEnabled(false);
            jxBtnSave.setEnabled(false);
            jxBtnCancel.setEnabled(false);

            jxBtnAdd.setEnabled(true);
            jxBtnUpdate.setEnabled(true);
            jxBtnDelete.setEnabled(true);
        }
        else
        {
            jxCbSemester.setEnabled(true);
            jxCbYear.setEnabled(true);
            
            jxDpDateDealineFee.setEditable(true);
            jxDpDateDealinePromation.setEditable(true);
            jxDpDateDealineRegistration.setEditable(true);
            jxDpDateStartRegistration.setEditable(true);
            
            jxSpRatePromotion.setEnabled(true);
            jxBtnSave.setEnabled(true);
            jxBtnCancel.setEnabled(true);
            

            jxBtnAdd.setEnabled(false);
            jxBtnUpdate.setEnabled(false);
            jxBtnDelete.setEnabled(false);
        }
    }
    
    private void prepare(){
      
        //Set lai text cac button cua dialog
        UIManager.put("OptionPane.cancelButtonText", "Hủy");
        UIManager.put("OptionPane.noButtonText", "Không");
        UIManager.put("OptionPane.okButtonText", "Có");
        UIManager.put("OptionPane.yesButtonText", "Vâng");
        //
        
//        jxDpDateDealineFee.addKeyListener(new KeyAdapter() {
//                public void keyTyped(KeyEvent e) {
//                    int len = jxDpDateDealineFee.getEditor().getText().length();
//                    if (len > 10) {
//                            e.consume();
//                    }
//                }
//        });
        this.m_InfoSemesterYearBLL = new InfoSemesterYearBLL();
        this.m_SemesterBLL = new SemesterBLL();
        this.m_AcademicYearBLL = new AcademicYearBLL();
        bindingDataToComboBox();
         
        m_Model = (DefaultTableModel)jxtabDetails.getModel();
        DataTable.addRowInfoSemesterYear(m_InfoSemesterYearBLL.getAllInfoSemesterYear(), listSemesterObj , listYearObj ,  m_Model);
        //get selected item
        jxtabDetails.setDefaultRenderer(Object.class, new MyTableCellRender());
        jxtabDetails.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
            @Override
            public void valueChanged(ListSelectionEvent lse) {
               
                if(!(jxtabDetails.getSelectionModel().isSelectionEmpty( )))
                {
                    //retrieving the selected row index
                    currentRow = jxtabDetails.getSelectedRow();
                    //if a single row is selected from the table, take each cell values into the controls
                    if (jxtabDetails.getRowSelectionAllowed()&&jxtabDetails.getRowCount()>0) {
                        if(jxtabDetails.m_isAdd||jxtabDetails.m_isUpdate)
                        {
                            int rs = JOptionPane.showOptionDialog(null,
                                        "Vui lòng lưu thay đổi trước khi chuyển sang dòng khác!",
                                        "Cảnh báo",
                                        JOptionPane.YES_NO_OPTION,
                                        JOptionPane.QUESTION_MESSAGE,
                                        null,
                                        null,
                                        null);
                            if(rs == 0 )//Yes
                            {
                                save();
                            }
                            else
                            {
                                cancelAction();
                            }
                        }
                        else
                        {
                            bindingDataToControls();
                        }
                    }
                }
            }
          });
        //neu co dl thi do mac dinh row dau tien
        if(jxtabDetails.getRowCount()>0)
        {
            jxtabDetails.setRequestFocusEnabled(true);
            jxtabDetails.requestFocus();
            jxtabDetails.changeSelection(jxtabDetails.getRowCount()-1, jxtabDetails.getRowCount()-1, false, false);
        }
    }
    
    private void bindingDataToComboBox()
    {
         //ComboxBox Hoc ky
        listSemesterObj = m_SemesterBLL.getAllSemesterToArray();
        objAddNewSemester = new SemesterDTO("HKThemMoi", "Thêm mới...");
        listSemesterObj.add(objAddNewSemester);
        DefaultComboBoxModel dfCbModelS = new DefaultComboBoxModel(listSemesterObj.toArray());
        jxCbSemester.setModel(dfCbModelS);
        
        //ComboxBox Nam Hoc
         listYearObj = m_AcademicYearBLL.getAllAcademicYearToArray();
        objAddNewYear = new AcademicYearDTO("NHThemMoi", "Thêm mới...");
        listYearObj.add(objAddNewYear);
        DefaultComboBoxModel dfCbModel = new DefaultComboBoxModel(listYearObj.toArray());
        jxCbYear.setModel(dfCbModel);
    }
    
    private void bindingDataToControls()
    {
        if(jxtabDetails.getRowCount()>0){
            String strMajorID = jxtabDetails.getValueAt(currentRow, 0).toString();
            jxTxtInfoSemesterYearID.setText(strMajorID);

            //Combobox Hoc Ky
            if (!jxtabDetails.getValueAt(currentRow, 1).equals("")) {
                SemesterDTO objSemester = (SemesterDTO)jxtabDetails.getValueAt(currentRow, 1);
                jxCbSemester.setSelectedItem(objSemester);
            }
            //ComboBox Nam hoc
            if (!jxtabDetails.getValueAt(currentRow, 2).equals("")) {
                AcademicYearDTO objAcademicYear = (AcademicYearDTO) jxtabDetails.getValueAt(currentRow, 2);
                jxCbYear.setSelectedItem(objAcademicYear);
            }

             if(!jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 3).equals(""))
            {
                try {
                    jxDpDateStartRegistration.setDate(formatDate.parse(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 3)));
                } catch (ParseException ex) {
                   ex.printStackTrace();
                }
            }
              if(!jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 5).equals(""))
            {
                try {
                    jxDpDateDealineRegistration.setDate(formatDate.parse(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 4)));
                } catch (ParseException ex) {
                   ex.printStackTrace();
                }
            }
               if(!jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 5).equals(""))
            {
                try {
                    jxDpDateDealineFee.setDate(formatDate.parse(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 5)));
                } catch (ParseException ex) {
                   ex.printStackTrace();
                }
            }
                if(!jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 6).equals(""))
            {
                try {
                    jxDpDateDealinePromation.setDate(formatDate.parse(jxtabDetails.getStringAt(jxtabDetails.getSelectedRow(), 6)));
                } catch (ParseException ex) {
                   ex.printStackTrace();
                }
            }
            //Ti le khuyen khich khi dong hoc phi
            if(!jxtabDetails.getValueAt(currentRow, 7).equals(""))
            {   
                jxSpRatePromotion.setValue(jxtabDetails.getValueAt(currentRow, 7));
            }

        }
    }
     
    /**
     * Ham xoa 1 khoa dc chon
     * @param rowSelected
     * @return 
     */
    private boolean isDelete(int rowSelected)
    {
        boolean m_isDelete = false;

        String id = this.jxtabDetails.getValueAt(rowSelected, 0).toString();

        if(m_InfoSemesterYearBLL.deleteInfoSemesterYearFromDatabase(id)){
            m_Model.removeRow(rowSelected);
            m_isDelete = true;
        }

        return m_isDelete;
    }
     /**
      * Ham xoa 1 luc nhieu khoa
      * @return 
      */
    private boolean isDeleteMoreInfoSemesterYear()
    {
        boolean m_isDelete = true;
        int[] arrRowSelected = this.jxtabDetails.getSelectedRows();
        for(int i = arrRowSelected.length - 1; i >=0; i--)
        {
            if(!isDelete(arrRowSelected[i])){
                JOptionPane.showMessageDialog(null, 
                        "Xóa thất bại khoa: "+ jxtabDetails.getValueAt(arrRowSelected[i], 1) , 
                        "Lỗi", 
                        JOptionPane.YES_OPTION);
                m_isDelete = false;
            }
        }
        return m_isDelete;
    }
    /**
     * Ham thuc hien insert Khoa xuong database
     * @return 
     */
    private void saveToDatabase()
    {
        if(checkData())
        {          
            String id = "HKNH00***";
            SemesterDTO objSemester = (SemesterDTO)jxCbSemester.getSelectedItem();
            AcademicYearDTO objAcademicYear = (AcademicYearDTO)jxCbYear.getSelectedItem();
            java.sql.Date dateStartCourseRegistration = new java.sql.Date(jxDpDateStartRegistration.getDate().getYear(), 
                    jxDpDateStartRegistration.getDate().getMonth(),jxDpDateStartRegistration.getDate().getDate());
            java.sql.Date dateDealineCourseRegistration = new java.sql.Date(jxDpDateDealineRegistration.getDate().getYear(), 
                    jxDpDateDealineRegistration.getDate().getMonth(),jxDpDateDealineRegistration.getDate().getDate());
            java.sql.Date dateDealineFee = new java.sql.Date(jxDpDateDealineFee.getDate().getYear(), 
                    jxDpDateDealineFee.getDate().getMonth(),jxDpDateDealineFee.getDate().getDate());
            java.sql.Date dateDealinePromation = new java.sql.Date(jxDpDateDealinePromation.getDate().getYear(), 
                    jxDpDateDealinePromation.getDate().getMonth(),jxDpDateDealinePromation.getDate().getDate());
            int ratePromotion = (int) jxSpRatePromotion.getValue();

            InfoSemesterYearDTO info = new InfoSemesterYearDTO();
            info.setInfoSemesterYearID(id);
            info.setSemesterID(objSemester.getSemesterID());
            info.setAcademicYearID(objAcademicYear.getAcademicYearID());
            info.setDateStartCourseRegistration(dateStartCourseRegistration);
            info.setDealineCourseRegistration(dateDealineCourseRegistration);
            info.setDealineFee(dateDealineFee);
            info.setDealinePromation(dateDealinePromation);
            info.setRatePromotion(ratePromotion);
            
            if(m_InfoSemesterYearBLL.checkInfoSemesterYearIsHaveInDatabase(info.getSemesterID(), info.getAcademicYearID())){
                if(m_InfoSemesterYearBLL.insertInfoSemesterYearToDatabase(info))
                {
                    JOptionPane.showOptionDialog(null, 
                        "Lưu xuống thành công!", 
                        "Thông báo", 
                        JOptionPane.YES_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        null,
                        null);
                    //neu luu thanh cong
                    this.jxtabDetails.m_isAdd = false;
                    initControls();
                    refreshDataInJTable();
                }
                else
                    JOptionPane.showMessageDialog(null, "Lưu xuống thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
            }else{
                JOptionPane.showMessageDialog(null, "Dữ liệu về '" + 
                        objSemester.getNameOfSemester() + 
                        "-" + objAcademicYear.getNameOfAcademicYear() + 
                        "' đã tồn tại!");
            }
        }
    }

    /**
     * Ham thuc hien cap nhat Khoa
     * @return 
     */
    private void updateToDatabase()
    {
        if(checkData())
        {    
            String id = this.jxTxtInfoSemesterYearID.getText().trim();
            SemesterDTO objSemester = (SemesterDTO)jxCbSemester.getSelectedItem();
            AcademicYearDTO objAcademicYear = (AcademicYearDTO)jxCbYear.getSelectedItem();
            java.sql.Date dateStartCourseRegistration = new java.sql.Date(jxDpDateStartRegistration.getDate().getYear(), 
                    jxDpDateStartRegistration.getDate().getMonth(),jxDpDateStartRegistration.getDate().getDate());
            java.sql.Date dateDealineCourseRegistration = new java.sql.Date(jxDpDateDealineRegistration.getDate().getYear(), 
                    jxDpDateDealineRegistration.getDate().getMonth(),jxDpDateDealineRegistration.getDate().getDate());
            java.sql.Date dateDealineFee = new java.sql.Date(jxDpDateDealineFee.getDate().getYear(), 
                    jxDpDateDealineFee.getDate().getMonth(),jxDpDateDealineFee.getDate().getDate());
            java.sql.Date dateDealinePromation = new java.sql.Date(jxDpDateDealinePromation.getDate().getYear(), 
                    jxDpDateDealinePromation.getDate().getMonth(),jxDpDateDealinePromation.getDate().getDate());
            int ratePromotion = (int) jxSpRatePromotion.getValue();
            
            InfoSemesterYearDTO info = new InfoSemesterYearDTO();
            info.setInfoSemesterYearID(id);
            info.setSemesterID(objSemester.getSemesterID());
            info.setAcademicYearID(objAcademicYear.getAcademicYearID());
            info.setDateStartCourseRegistration(dateStartCourseRegistration);
            info.setDealineCourseRegistration(dateDealineCourseRegistration);
            info.setDealineFee(dateDealineFee);
            info.setDealinePromation(dateDealinePromation);
            info.setRatePromotion(ratePromotion);
            
            if(m_InfoSemesterYearBLL.updateInfoSemesterYearToDatabase(info))
                {
                    JOptionPane.showOptionDialog(null, 
                     "Câp nhật thành công!", 
                     "Thông báo", 
                     JOptionPane.YES_OPTION,
                     JOptionPane.QUESTION_MESSAGE,
                     null,
                     null,
                     null);
                     //neu Cập nhật thanh cong
                    this.jxtabDetails.m_isUpdate = false;
                    initControls();
                    refreshDataInJTable();
                }
                else
                 JOptionPane.showMessageDialog(null, "Cập nhật thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
        
                
        }
    }
     /**
     * Ham thuc hien viec cap nhat va update
     */
     private void save()
    {
         if(this.jxtabDetails.m_isAdd)
        {
            saveToDatabase();
        }
        else
            if(this.jxtabDetails.m_isUpdate)
            {
                updateToDatabase();
            }
    }
    
    private void cancelAction()
     {
         if(this.jxtabDetails.m_isAdd){
            ((DefaultTableModel)jxtabDetails.getModel()).removeRow(jxtabDetails.getRowCount()-1);
            this.jxtabDetails.m_isAdd = false;
            initControls();
            jxTxtInfoSemesterYearID.setText("");
            jxSpRatePromotion.setValue(0);
            jxtabDetails.changeSelection(jxtabDetails.getRowCount()-1, jxtabDetails.getRowCount()-1, false, false);
        }
        else
        {     
           this.jxtabDetails.m_isUpdate = false;
           initControls(); 
        }
        refreshDataInJTable();
     
     }
   
    private void refreshDataInJTable()
    {
        m_Model.fireTableDataChanged();
        m_Model.fireTableStructureChanged();
        m_Model.getDataVector().removeAllElements();
        DataTable.addRowInfoSemesterYear(m_InfoSemesterYearBLL.getAllInfoSemesterYear(), listSemesterObj , listYearObj ,  m_Model);
        if(jxtabDetails.getRowCount()>0)
        {
            jxtabDetails.setRequestFocusEnabled(true);
            jxtabDetails.requestFocus();
            jxtabDetails.changeSelection(jxtabDetails.getRowCount()-1, jxtabDetails.getRowCount()-1, false, false);
        }
    }
    
    private boolean checkData()
    {
        if(jxCbSemester.getSelectedIndex()==-1||
                jxCbYear.getSelectedIndex()==-1||
                jxDpDateDealineFee.getDate() == null||
                jxDpDateDealinePromation.getDate() == null||
                jxDpDateDealineRegistration.getDate() == null||
                jxDpDateStartRegistration.getDate() == null||
                jxSpRatePromotion.getValue() == null){
            JOptionPane.showOptionDialog(null,
                    "Dữ liệu không được bỏ trống. Vui lòng nhập lại!", 
                    "Cảnh báo",
                    JOptionPane.YES_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null,
                    null,
                    null);
            return false;
        }
        //Kiem tra ngay nhap vao co hop le hay ko?
        if(Standard.compareDate(jxDpDateStartRegistration.getDate(), Standard.getDateSystem()) == 2||
                Standard.compareDate(jxDpDateStartRegistration.getDate(), Standard.getDateSystem()) == 0) {///ngay BD DK sau hoac bang ngay hien tai
             if(Standard.compareDate(jxDpDateDealineRegistration.getDate(),jxDpDateStartRegistration.getDate())== 2)//ngay het han dk phai lon hon ngay bat dk
            {
                if(Standard.compareDate(jxDpDateDealineFee.getDate(), jxDpDateDealineRegistration.getDate()) == 2)//ngay kt dong hoc phi phai lon hon ngay het han dk mon hoc
                {   
                    if(Standard.compareDate(jxDpDateDealineFee.getDate(), jxDpDateDealinePromation.getDate()) == 2)//ngay ket thu dong hoc phi phai lon hon ngay kt khuyen khich
                        return true;
                    else
                    {
                        JOptionPane.showOptionDialog(null,
                        "Ngày kết thúc đóng học phí phải lớn hơn ngày kết thúc khuyến khích!", 
                        "Cảnh báo",
                        JOptionPane.YES_OPTION,
                        JOptionPane.WARNING_MESSAGE,
                        null,
                        null,
                        null);
                        return false;
                    }
                }
                else{
                    JOptionPane.showOptionDialog(null,
                    "Ngày kết thúc đóng học phí phải lớn hơn ngày kết thúc đăng ký môn học!", 
                    "Cảnh báo",
                    JOptionPane.YES_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null,
                    null,
                    null);
                    return false;
                }
                    
            }else{
                JOptionPane.showOptionDialog(null,
                    "Ngày kết thúc đăng ký phải lớn hơn ngày bắt đầu đăng ký môn học!", 
                    "Cảnh báo",
                    JOptionPane.YES_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null,
                    null,
                    null);
                return false;
            }
        } else {
             JOptionPane.showOptionDialog(null,
                    "Ngày bắt đầu đăng ký phải không nhỏ hơn ngày hiện tại!", 
                    "Cảnh báo",
                    JOptionPane.YES_OPTION,
                    JOptionPane.WARNING_MESSAGE,
                    null,
                    null,
                    null);
            return false;
        }
       
    }
   
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        jxpanDetails = new org.jdesktop.swingx.JXPanel();
        jpanTableDetails = new javax.swing.JPanel();
        jpanContent = new javax.swing.JPanel();
        jxpanFindNavibar = new org.jdesktop.swingx.JXPanel();
        jpanChose = new javax.swing.JPanel();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jxbtnFindVisible = new org.jdesktop.swingx.JXButton();
        jxSearchFaculty = new org.jdesktop.swingx.JXSearchField();
        jXLabel1 = new org.jdesktop.swingx.JXLabel();
        jScrollPane = new javax.swing.JScrollPane();
        jxtabDetails = new mnstudent.global.MyTable();
        jpanFuntionalDetails = new javax.swing.JPanel();
        jxBtnAdd = new org.jdesktop.swingx.JXButton();
        jxBtnUpdate = new org.jdesktop.swingx.JXButton();
        jxBtnDelete = new org.jdesktop.swingx.JXButton();
        jxBtnSave = new org.jdesktop.swingx.JXButton();
        jxBtnCancel = new org.jdesktop.swingx.JXButton();
        jxpanHeader = new org.jdesktop.swingx.JXPanel();
        jxpanTitleHeader = new org.jdesktop.swingx.JXPanel();
        jXLabel5 = new org.jdesktop.swingx.JXLabel();
        jxpanInfoHeader = new org.jdesktop.swingx.JXPanel();
        jxpanInfo = new org.jdesktop.swingx.JXPanel();
        jxLabFacultyID = new org.jdesktop.swingx.JXLabel();
        jxTxtInfoSemesterYearID = new org.jdesktop.swingx.JXTextField();
        jxLabNameOfFaculty = new org.jdesktop.swingx.JXLabel();
        jxLabNameOfFaculty1 = new org.jdesktop.swingx.JXLabel();
        jxSpRatePromotion = new javax.swing.JSpinner();
        jxCbSemester = new org.jdesktop.swingx.JXComboBox();
        jxLabNameOfFaculty2 = new org.jdesktop.swingx.JXLabel();
        jxCbYear = new org.jdesktop.swingx.JXComboBox();
        jxLabNameOfFaculty3 = new org.jdesktop.swingx.JXLabel();
        jxDpDateStartRegistration = new org.jdesktop.swingx.JXDatePicker();
        jxDpDateDealineRegistration = new org.jdesktop.swingx.JXDatePicker();
        jxLabNameOfFaculty4 = new org.jdesktop.swingx.JXLabel();
        jxDpDateDealinePromation = new org.jdesktop.swingx.JXDatePicker();
        jxLabNameOfFaculty5 = new org.jdesktop.swingx.JXLabel();
        jxDpDateDealineFee = new org.jdesktop.swingx.JXDatePicker();
        jxLabNameOfFaculty6 = new org.jdesktop.swingx.JXLabel();

        setLayout(new java.awt.BorderLayout());

        jxpanDetails.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanDetails.setLayout(new java.awt.BorderLayout());

        jpanTableDetails.setLayout(new java.awt.BorderLayout());

        jpanContent.setLayout(new java.awt.BorderLayout());

        jxpanFindNavibar.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanFindNavibar.setPreferredSize(new java.awt.Dimension(914, 30));

        jpanChose.setBorder(javax.swing.BorderFactory.createTitledBorder("Chọn nội dung tìm kiếm"));

        jCheckBox3.setText("Tìm theo học kỳ");

        jCheckBox2.setText("Tìm theo năm học");

        jCheckBox1.setText("Tìm kiếm nhanh");

        javax.swing.GroupLayout jpanChoseLayout = new javax.swing.GroupLayout(jpanChose);
        jpanChose.setLayout(jpanChoseLayout);
        jpanChoseLayout.setHorizontalGroup(
            jpanChoseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanChoseLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jCheckBox3)
                .addGap(30, 30, 30)
                .addComponent(jCheckBox2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 633, Short.MAX_VALUE)
                .addComponent(jCheckBox1)
                .addGap(105, 105, 105))
        );
        jpanChoseLayout.setVerticalGroup(
            jpanChoseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jpanChoseLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jCheckBox3)
                .addComponent(jCheckBox1)
                .addComponent(jCheckBox2))
        );

        jxbtnFindVisible.setBorder(javax.swing.BorderFactory.createEmptyBorder(1, 1, 1, 1));
        jxbtnFindVisible.setText("Tùy chọn");
        jxbtnFindVisible.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxbtnFindVisibleActionPerformed(evt);
            }
        });

        jXLabel1.setText("Tìm kiếm:");

        javax.swing.GroupLayout jxpanFindNavibarLayout = new javax.swing.GroupLayout(jxpanFindNavibar);
        jxpanFindNavibar.setLayout(jxpanFindNavibarLayout);
        jxpanFindNavibarLayout.setHorizontalGroup(
            jxpanFindNavibarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jxpanFindNavibarLayout.createSequentialGroup()
                .addComponent(jxbtnFindVisible, javax.swing.GroupLayout.PREFERRED_SIZE, 60, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jxSearchFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(jpanChose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        jxpanFindNavibarLayout.setVerticalGroup(
            jxpanFindNavibarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanFindNavibarLayout.createSequentialGroup()
                .addGroup(jxpanFindNavibarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxbtnFindVisible, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxSearchFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jXLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jpanChose, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jpanContent.add(jxpanFindNavibar, java.awt.BorderLayout.NORTH);

        jxtabDetails.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Mã thông tin học kỳ - năm học", "Học kỳ", "Năm học", "Ngày bắt đầu đk môn học", "Ngày kết thúc đk môn học", "Ngày kết thúc đóng HP", "Ngày kết thúc KK", "Tỉ lệ khuyến khích"
            }
        ) {
            Class[] types = new Class [] {
                java.lang.String.class, java.lang.Object.class, java.lang.Object.class, java.lang.String.class, java.lang.Object.class, java.lang.String.class, java.lang.String.class, java.lang.String.class
            };
            boolean[] canEdit = new boolean [] {
                false, true, true, true, true, true, true, true
            };

            public Class getColumnClass(int columnIndex) {
                return types [columnIndex];
            }

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jxtabDetails.setGridColor(new java.awt.Color(153, 153, 153));
        jxtabDetails.setSelectionBackground(new java.awt.Color(204, 204, 204));
        jxtabDetails.setSortsOnUpdates(false);
        jScrollPane.setViewportView(jxtabDetails);

        jpanContent.add(jScrollPane, java.awt.BorderLayout.CENTER);

        jpanTableDetails.add(jpanContent, java.awt.BorderLayout.CENTER);

        jpanFuntionalDetails.setLayout(new java.awt.GridBagLayout());

        jxBtnAdd.setText("Thêm mới");
        jxBtnAdd.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnAddActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(8, 10, 6, 9);
        jpanFuntionalDetails.add(jxBtnAdd, gridBagConstraints);

        jxBtnUpdate.setText("Sửa đổi");
        jxBtnUpdate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnUpdateActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 2;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTH;
        gridBagConstraints.insets = new java.awt.Insets(8, 10, 6, 8);
        jpanFuntionalDetails.add(jxBtnUpdate, gridBagConstraints);

        jxBtnDelete.setText("Xóa bỏ");
        jxBtnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnDeleteActionPerformed(evt);
            }
        });
        jxBtnDelete.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                jxBtnDeleteAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 3;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(10, 10, 4, 8);
        jpanFuntionalDetails.add(jxBtnDelete, gridBagConstraints);

        jxBtnSave.setText("Lưu xuống");
        jxBtnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnSaveActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 4;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(11, 9, 7, 8);
        jpanFuntionalDetails.add(jxBtnSave, gridBagConstraints);

        jxBtnCancel.setText("Hủy bỏ");
        jxBtnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxBtnCancelActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 5;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 20;
        gridBagConstraints.ipady = 6;
        gridBagConstraints.insets = new java.awt.Insets(12, 9, 8, 9);
        jpanFuntionalDetails.add(jxBtnCancel, gridBagConstraints);

        jpanTableDetails.add(jpanFuntionalDetails, java.awt.BorderLayout.EAST);

        jxpanDetails.add(jpanTableDetails, java.awt.BorderLayout.CENTER);

        add(jxpanDetails, java.awt.BorderLayout.CENTER);

        jxpanHeader.setLayout(new java.awt.BorderLayout());

        jxpanTitleHeader.setBorder(new org.jdesktop.swingx.border.DropShadowBorder());

        jXLabel5.setForeground(new java.awt.Color(0, 102, 255));
        jXLabel5.setText("THÔNG TIN HỌC KỲ - NĂM HỌC");
        jXLabel5.setFont(new java.awt.Font("Times New Roman", 1, 24)); // NOI18N
        jxpanTitleHeader.add(jXLabel5);

        jxpanHeader.add(jxpanTitleHeader, java.awt.BorderLayout.PAGE_START);

        jxpanInfoHeader.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jxpanInfoHeader.setLayout(new java.awt.BorderLayout());

        jxpanInfo.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "THÔNG TIN", javax.swing.border.TitledBorder.LEFT, javax.swing.border.TitledBorder.TOP));

        jxLabFacultyID.setText("Mã thông tin học kỳ - năm học");

        jxTxtInfoSemesterYearID.addCaretListener(new javax.swing.event.CaretListener() {
            public void caretUpdate(javax.swing.event.CaretEvent evt) {
                jxTxtInfoSemesterYearIDCaretUpdate(evt);
            }
        });

        jxLabNameOfFaculty.setText("Học kỳ ");

        jxLabNameOfFaculty1.setText("Tỉ lệ khuyến khích học phí");

        jxSpRatePromotion.setModel(new javax.swing.SpinnerNumberModel(0, 0, 100, 1));
        jxSpRatePromotion.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                jxSpRatePromotionStateChanged(evt);
            }
        });
        jxSpRatePromotion.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jxSpRatePromotionKeyPressed(evt);
            }
        });

        jxCbSemester.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jxCbSemesterItemStateChanged(evt);
            }
        });

        jxLabNameOfFaculty2.setText("Năm học");

        jxCbYear.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jxCbYearItemStateChanged(evt);
            }
        });

        jxLabNameOfFaculty3.setText("Ngày bắt đầu đăng ký môn học");

        jxDpDateStartRegistration.setFormats("dd/MM/yyyy");
        jxDpDateStartRegistration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxDpDateStartRegistrationActionPerformed(evt);
            }
        });

        jxDpDateDealineRegistration.setFormats("dd/MM/yyyy");
        jxDpDateDealineRegistration.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxDpDateDealineRegistrationActionPerformed(evt);
            }
        });

        jxLabNameOfFaculty4.setText("Ngày kết thúc đăng ký môn học");

        jxDpDateDealinePromation.setFormats("dd/MM/yyyy");
        jxDpDateDealinePromation.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxDpDateDealinePromationActionPerformed(evt);
            }
        });

        jxLabNameOfFaculty5.setText("Ngày kết thúc khuyến khích");

        jxDpDateDealineFee.setFormats("dd/MM/yyyy");
        jxDpDateDealineFee.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jxDpDateDealineFeeActionPerformed(evt);
            }
        });

        jxLabNameOfFaculty6.setText("Ngày kết thúc đóng học phí");

        javax.swing.GroupLayout jxpanInfoLayout = new javax.swing.GroupLayout(jxpanInfo);
        jxpanInfo.setLayout(jxpanInfoLayout);
        jxpanInfoLayout.setHorizontalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jxpanInfoLayout.createSequentialGroup()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jxLabNameOfFaculty3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxLabFacultyID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(20, 20, 20)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jxTxtInfoSemesterYearID, javax.swing.GroupLayout.PREFERRED_SIZE, 157, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jxDpDateStartRegistration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(130, 130, 130))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addComponent(jxLabNameOfFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jxDpDateDealineRegistration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(110, 110, 110)))
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jxpanInfoLayout.createSequentialGroup()
                                .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(jxCbSemester, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jxpanInfoLayout.createSequentialGroup()
                                .addComponent(jxLabNameOfFaculty5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jxDpDateDealinePromation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(130, 130, 130)
                        .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jxpanInfoLayout.createSequentialGroup()
                                .addComponent(jxLabNameOfFaculty1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jxSpRatePromotion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jxpanInfoLayout.createSequentialGroup()
                                .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jxCbYear, javax.swing.GroupLayout.PREFERRED_SIZE, 125, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(jxpanInfoLayout.createSequentialGroup()
                        .addComponent(jxLabNameOfFaculty6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jxDpDateDealineFee, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(171, 171, 171))
        );
        jxpanInfoLayout.setVerticalGroup(
            jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jxpanInfoLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jxLabFacultyID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxTxtInfoSemesterYearID, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxCbSemester, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxLabNameOfFaculty2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jxCbYear, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jxLabNameOfFaculty3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jxDpDateStartRegistration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jxDpDateDealineFee, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jxLabNameOfFaculty6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(18, 18, 18)
                .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jxLabNameOfFaculty5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jxDpDateDealinePromation, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jxLabNameOfFaculty1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jxSpRatePromotion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jxpanInfoLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jxLabNameOfFaculty4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jxDpDateDealineRegistration, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(0, 9, Short.MAX_VALUE))
        );

        jxpanInfoHeader.add(jxpanInfo, java.awt.BorderLayout.CENTER);

        jxpanHeader.add(jxpanInfoHeader, java.awt.BorderLayout.CENTER);

        add(jxpanHeader, java.awt.BorderLayout.NORTH);
    }// </editor-fold>//GEN-END:initComponents

    private void jxbtnFindVisibleActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxbtnFindVisibleActionPerformed
        if(jxbtnFindVisible.getText().equals("Đóng"))
        {
          jxbtnFindVisible.setPreferredSize(new Dimension(110,25));
          jxbtnFindVisible.setText("Tùy chọn");
          jxbtnFindVisible.revalidate();
          jxpanFindNavibar.setPreferredSize(new Dimension(30, 30));
          jxpanFindNavibar.revalidate();
        }
        else
        {
            jxbtnFindVisible.setPreferredSize(new Dimension(20, 25));
            jxbtnFindVisible.setText("Đóng");
            jxbtnFindVisible.revalidate();
            jxpanFindNavibar.setPreferredSize(new Dimension(30, 105));
            jxpanFindNavibar.revalidate();
        }
    }//GEN-LAST:event_jxbtnFindVisibleActionPerformed

    private void jxBtnDeleteAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_jxBtnDeleteAncestorAdded
        // TODO add your handling code here:
    }//GEN-LAST:event_jxBtnDeleteAncestorAdded

    private void jxBtnAddActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnAddActionPerformed
       if(jxtabDetails.getRowCount()>0){        
            for (int i = 0; i < jxtabDetails.getColumnCount(); i++) {
                if(jxtabDetails.getValueAt(jxtabDetails.getRowCount()-1, i).equals(""))
                    return;
            }
       }
        Vector newRow = new Vector(jxtabDetails.getColumnCount());
        for (int i = 0; i < jxtabDetails.getColumnCount(); i++) {
            newRow.addElement("");
        }
        ((DefaultTableModel)jxtabDetails.getModel()).addRow(newRow);
        jxtabDetails.setRowSelectionInterval(jxtabDetails.getRowCount()-1,jxtabDetails.getRowCount()-1);
        //jxtabDetails.setEnabled(false);
        //jxtabDetails.setRowSelectionAllowed(false);
        JScrollBar sb = jScrollPane.getVerticalScrollBar();
        sb.setValue( sb.getMaximum());
        
        if(!this.jxtabDetails.m_isAdd){           
           this.jxtabDetails.m_isAdd = true;
           initControls();
           this.jxtabDetails.m_rowIndex = jxtabDetails.getRowCount()-1;
           resetControls();
        }
    }//GEN-LAST:event_jxBtnAddActionPerformed

    private void resetControls()
    {
       jxTxtInfoSemesterYearID.setText("HKNH00***");
       jxCbSemester.requestFocus();
       jxSpRatePromotion.setValue(0);
       jxCbSemester.setSelectedItem(null);
       jxCbYear.setSelectedItem(null);
       jxDpDateDealineFee.setDate(null);
       jxDpDateDealinePromation.setDate(null);
       jxDpDateDealineRegistration.setDate(null);
       jxDpDateStartRegistration.setDate(null);
    }
    private void jxTxtInfoSemesterYearIDCaretUpdate(javax.swing.event.CaretEvent evt) {//GEN-FIRST:event_jxTxtInfoSemesterYearIDCaretUpdate
     
       if(this.jxtabDetails.m_isAdd)
            jxtabDetails.getModel().setValueAt(jxTxtInfoSemesterYearID.getText(), jxtabDetails.getRowCount()-1, 0);
        else
            if(this.jxtabDetails.m_isUpdate)
                jxtabDetails.getModel().setValueAt(jxTxtInfoSemesterYearID.getText(), jxtabDetails.getSelectedRow(), 0);
    }//GEN-LAST:event_jxTxtInfoSemesterYearIDCaretUpdate

    private void jxBtnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnCancelActionPerformed
        
        cancelAction();
    }//GEN-LAST:event_jxBtnCancelActionPerformed

    private void jxBtnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnSaveActionPerformed
        
        save();
    }//GEN-LAST:event_jxBtnSaveActionPerformed

    private void jxBtnUpdateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnUpdateActionPerformed

        this.jxtabDetails.m_isUpdate = true;
        initControls();
        jxCbSemester.requestFocus();
    }//GEN-LAST:event_jxBtnUpdateActionPerformed

    private void jxBtnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxBtnDeleteActionPerformed
          
        int rs = JOptionPane.showOptionDialog(null, 
                        "Bạn có muốn xóa không!", 
                        "Câu hỏi", 
                        JOptionPane.YES_NO_OPTION,
                        JOptionPane.QUESTION_MESSAGE,
                        null,
                        null,
                        null);
        if(rs == 0)
        {
            if(isDeleteMoreInfoSemesterYear())
            {
                JOptionPane.showOptionDialog(null, 
                        "Xóa thành công!", 
                        "Thông báo", 
                        JOptionPane.YES_OPTION,
                        JOptionPane.INFORMATION_MESSAGE,
                        null,
                        null,
                        null);
                 //neu luu thanh cong
                this.jxtabDetails.m_isAdd = false;
                initControls();
                refreshDataInJTable();
            }
            else
                 JOptionPane.showMessageDialog(null, "Xóa thất bại. Vui lòng kiểm tra lại!", "Lỗi", JOptionPane.YES_OPTION);
        }
    }//GEN-LAST:event_jxBtnDeleteActionPerformed

    private void jxSpRatePromotionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jxSpRatePromotionKeyPressed
        if(evt.getKeyCode() == KeyEvent.VK_ENTER)
            JOptionPane.showMessageDialog(null, "dsadksandlkna lkansdka");
    }//GEN-LAST:event_jxSpRatePromotionKeyPressed

    private void jxCbSemesterItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jxCbSemesterItemStateChanged
        if(jxCbSemester.getSelectedItem() != null)
        {
            SemesterDTO obj = (SemesterDTO) evt.getItem();
            if (obj.equals(objAddNewSemester)) {
                JOptionPane.showMessageDialog(null, "Thêm mới HOC KY!");
                jxCbSemester.setSelectedItem(null);
            } else {
                if (this.jxtabDetails.m_isAdd || this.jxtabDetails.m_isUpdate) {
                    jxtabDetails.getModel().setValueAt(obj, currentRow, 1);
                }
            }
        }
    }//GEN-LAST:event_jxCbSemesterItemStateChanged

    private void jxCbYearItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jxCbYearItemStateChanged
        if(jxCbYear.getSelectedItem() != null)
        {
            AcademicYearDTO obj = (AcademicYearDTO) evt.getItem();
            if (obj.equals(objAddNewYear)) {
                JOptionPane.showMessageDialog(null, "Thêm mới NAM HOC!");
                jxCbYear.setSelectedItem(null);
            } else {
                if (this.jxtabDetails.m_isAdd || this.jxtabDetails.m_isUpdate) {
                    jxtabDetails.getModel().setValueAt(obj, currentRow, 2);
                }
            }
        }
    }//GEN-LAST:event_jxCbYearItemStateChanged

    private void jxDpDateStartRegistrationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxDpDateStartRegistrationActionPerformed
        if(jxtabDetails.m_isAdd||jxtabDetails.m_isUpdate)
        {
            String date = formatDate.format(jxDpDateStartRegistration.getDate());
            jxtabDetails.getModel().setValueAt(date, jxtabDetails.getSelectedRow(), 3);
        }
    }//GEN-LAST:event_jxDpDateStartRegistrationActionPerformed

    private void jxDpDateDealineRegistrationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxDpDateDealineRegistrationActionPerformed
        if(jxtabDetails.m_isAdd||jxtabDetails.m_isUpdate)
        {
            String date = formatDate.format(jxDpDateDealineRegistration.getDate());
            jxtabDetails.getModel().setValueAt(date, jxtabDetails.getSelectedRow(), 4);
        }
    }//GEN-LAST:event_jxDpDateDealineRegistrationActionPerformed

    private void jxDpDateDealineFeeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxDpDateDealineFeeActionPerformed
        if(jxtabDetails.m_isAdd||jxtabDetails.m_isUpdate)
        {
            String date = formatDate.format(jxDpDateDealineFee.getDate());
            jxtabDetails.getModel().setValueAt(date, jxtabDetails.getSelectedRow(), 5);
        }
    }//GEN-LAST:event_jxDpDateDealineFeeActionPerformed

    private void jxDpDateDealinePromationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jxDpDateDealinePromationActionPerformed
        if(jxtabDetails.m_isAdd||jxtabDetails.m_isUpdate)
        {
            String date = formatDate.format(jxDpDateDealinePromation.getDate());
            jxtabDetails.getModel().setValueAt(date, jxtabDetails.getSelectedRow(), 6);
        }
    }//GEN-LAST:event_jxDpDateDealinePromationActionPerformed

    private void jxSpRatePromotionStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_jxSpRatePromotionStateChanged
         if (this.jxtabDetails.m_isAdd) {
            jxtabDetails.getModel().setValueAt(jxSpRatePromotion.getValue(), jxtabDetails.getRowCount() - 1, 7);
        } else if (this.jxtabDetails.m_isUpdate) {
            jxtabDetails.getModel().setValueAt(jxSpRatePromotion.getValue(), jxtabDetails.getSelectedRow(), 7);
        }
    }//GEN-LAST:event_jxSpRatePromotionStateChanged


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JScrollPane jScrollPane;
    private org.jdesktop.swingx.JXLabel jXLabel1;
    private org.jdesktop.swingx.JXLabel jXLabel5;
    private javax.swing.JPanel jpanChose;
    private javax.swing.JPanel jpanContent;
    private javax.swing.JPanel jpanFuntionalDetails;
    private javax.swing.JPanel jpanTableDetails;
    private org.jdesktop.swingx.JXButton jxBtnAdd;
    private org.jdesktop.swingx.JXButton jxBtnCancel;
    private org.jdesktop.swingx.JXButton jxBtnDelete;
    private org.jdesktop.swingx.JXButton jxBtnSave;
    private org.jdesktop.swingx.JXButton jxBtnUpdate;
    private org.jdesktop.swingx.JXComboBox jxCbSemester;
    private org.jdesktop.swingx.JXComboBox jxCbYear;
    private org.jdesktop.swingx.JXDatePicker jxDpDateDealineFee;
    private org.jdesktop.swingx.JXDatePicker jxDpDateDealinePromation;
    private org.jdesktop.swingx.JXDatePicker jxDpDateDealineRegistration;
    private org.jdesktop.swingx.JXDatePicker jxDpDateStartRegistration;
    private org.jdesktop.swingx.JXLabel jxLabFacultyID;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty1;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty2;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty3;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty4;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty5;
    private org.jdesktop.swingx.JXLabel jxLabNameOfFaculty6;
    private org.jdesktop.swingx.JXSearchField jxSearchFaculty;
    private javax.swing.JSpinner jxSpRatePromotion;
    private org.jdesktop.swingx.JXTextField jxTxtInfoSemesterYearID;
    private org.jdesktop.swingx.JXButton jxbtnFindVisible;
    private org.jdesktop.swingx.JXPanel jxpanDetails;
    private org.jdesktop.swingx.JXPanel jxpanFindNavibar;
    private org.jdesktop.swingx.JXPanel jxpanHeader;
    private org.jdesktop.swingx.JXPanel jxpanInfo;
    private org.jdesktop.swingx.JXPanel jxpanInfoHeader;
    private org.jdesktop.swingx.JXPanel jxpanTitleHeader;
    private mnstudent.global.MyTable jxtabDetails;
    // End of variables declaration//GEN-END:variables
}
